package com.ler.yrmall.coupon.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ler.yrmall.basic.Form;
import com.ler.yrmall.coupon.entity.CouponHistoryEntity;
import com.ler.yrmall.coupon.mapper.CouponHistoryMapper;
import com.ler.yrmall.coupon.service.CouponHistoryService;
import com.ler.yrmall.coupon.vo.CouponHistoryVO;
import com.ler.yrmall.dto.LoginUser;
import com.ler.yrmall.utils.SecurityUtils;
import org.springframework.stereotype.Service;


/**
 * @author leron
 */
@Service
public class CouponHistoryServiceImpl extends ServiceImpl<CouponHistoryMapper, CouponHistoryEntity> implements CouponHistoryService {

    @Override
    public IPage<CouponHistoryVO> find(Form request) {
        return this.baseMapper.find(request.getPage(),request);
    }

    @Override
    public int getMemberReceiveCount(long couponId) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        return (int) this.count(Wrappers.<CouponHistoryEntity>lambdaQuery()
                .eq(CouponHistoryEntity::getCouponId,couponId)
                .eq(CouponHistoryEntity::getMemberId,loginUser.getId()));
    }
}